#include <stdlib.h>
#include "osdep/timer.h"
#include "input/input.h"
#include "input/mouse.h"


int key_fifo_size = 7;
static int *key_fifo_data = NULL;
static int key_fifo_read=0;
static int key_fifo_write=0;
unsigned doubleclick_time = 300;

void mplayer_put_key(int code){
  //printf("mplayer_put_key(%d)\n",code);
  if (key_fifo_data == NULL)
    key_fifo_data = malloc(key_fifo_size * sizeof(int));
  if(((key_fifo_write+1)%key_fifo_size)==key_fifo_read) return; // FIFO FULL!!
  key_fifo_data[key_fifo_write]=code;
  key_fifo_write=(key_fifo_write+1)%key_fifo_size;
}

int mplayer_get_key(int fd){
  int key;
  //printf("mplayer_get_key(%d)\n",fd);
  if (key_fifo_data == NULL)
    return MP_INPUT_NOTHING;
  if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
  key=key_fifo_data[key_fifo_read];
  key_fifo_read=(key_fifo_read+1)%key_fifo_size;
  //printf("mplayer_get_key => %d\n",key);
  return key;
}

